var t = getApp();

Page({
    data: {
        home_btn: t.home_btn,
        fontSize: t.fontSize,
        winHeight: "",
        currentTab: 0,
        scrollLeft: 0,
        picLayer: !1,
        list: [],
        listId: 0,
        isChoose: !1,
        chooseData: {},
        bigPicUrl: "",
        lastId: null,
        nextId: null,
        index: 0,
        pageData: [],
        server: "http://www.ylhzzy.top:8828/public",
        serverUrl: "http://www.ylhzzy.top:8828/public",
        showQRShare: t.showQRShare,
        showPrice: t.showPrice,
        cates: [],
        currCate: 0,
        pageSize: 15,
        watermark: ""
    },
    onLoad: function(a) {
        console.log("options", a);
        t.fromOptions(a);
        console.log("options", a);
        this.setData({
            options: a,
            route: this.route
        });
        console.log("#####################");
        console.log(typeof(a.id));
        var e = a.id, r = a.cateId;
        a.tid && (e = a.tid, r = a.tid), this.loadCates(Number(e), r, !0);
        var o = wx.getStorageSync("watermark");
        this.setData({
            watermark: o
        }), console.log("watermark", this.data.watermark);
    },
    loadCates: function(a, e, r) {
        var o = this;
        t.request({
            url: t.rserver + "/productApi/getProductCatList",
            method: "POST",
            data: {
                token: t.token
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var r = t.data.result.productCats;
                console.log("productCats", r);
                for (var s = 0; s < r.length; s++) {
                    var i = r[s].id === a, d = r[s].children, n = 0, c = 0, l = !0, u = !1, p = void 0;
                    try {
                        for (var h, g = d[Symbol.iterator](); !(l = (h = g.next()).done); l = !0) {
                            var f = h.value;
                            f.inited = !1, f.id === e && (n = c, i = !0), f.prds = [], f.currPage = 1, f.total = 0, 
                            f.ing = !1, c++;
                        }
                    } catch (t) {
                        u = !0, p = t;
                    } finally {
                        try {
                            !l && g.return && g.return();
                        } finally {
                            if (u) throw p;
                        }
                    }
                    console.log("~~~~~~~~~~~~~~~~~~~~~~~~");
                    console.log(typeof(r[s].id));
                    console.log(typeof(a));
                    if (i) 
                    {
                        if (o.setData({
                            currCate: n,
                            cates: d
                        }), wx.setNavigationBarTitle({
                            title: r[s].title
                        }), d.length > 0)
                        {
                            for (var v = 0; v < d.length; v++) 
                            {
                                o.loadPrds(v, 0);
                            }
                        } 
                        break;
                    }
                }
            }
        });
    },
    swichCate: function(t) {
        this.setData({
            "options.cateId": this.data.cates[t.currentTarget.dataset.index].id,
            currCate: t.currentTarget.dataset.index
        }), wx.setNavigationBarTitle({
            title: this.data.cates[t.currentTarget.dataset.index].title
        });
    },
    loadPrds: function(a, e) {
        console.log(this.data.pageSize);
        var r = this, o = this.data.cates[a], s = {};
        s["cates[" + a + "].ing"] = !0, this.setData(s), t.request({
            url: t.rserver + "/productApi/getProductCatInfo",
            method: "POST",
            data: {
                token: t.token,
                page_size: this.data.pageSize,
                id: o.id,
                cur_page: e
            },
            header: {
            },
            success: function(t) {
                var e = t.data.result.product;
                o.prds.push.apply(o.prds, e), (s = {})["cates[" + a + "].prds"] = o.prds, s["cates[" + a + "].total"] = Number(t.data.result.paginate.total_record), 
                s["cates[" + a + "].currPage"] = Number(t.data.result.paginate.cur_page), s["cates[" + a + "].ing"] = !1, 
                r.setData(s);
            }
        });
    },
    loadMore: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.cates[a];
        e.ing || e.total > e.prds.length && this.loadPrds(a, e.currPage + 1);
    },
    onShow: function() {},
    choose: function(t) {
        var a = t.currentTarget.dataset.id;
        console.log("e.currentTarget", t.currentTarget);
        var e = t.currentTarget.dataset.title;
        wx.navigateTo({
            url: "/pages/products/detail/detail?id=" + a + "&title=" + e
        });
    },
    choose1: function(a) {
        var e = this;
        console.log(a), t.request({
            url: t.server + "/productApi/getProductInfo",
            method: "POST",
            data: {
                id: a.currentTarget.dataset.id
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                console.log(t), e.setData({
                    picLayer: !0,
                    index: a.currentTarget.dataset.x,
                    chooseData: t.data.result.product,
                    lastId: 0 === t.data.result.product.last_id ? null : t.data.result.product.last_id,
                    nextId: 0 === t.data.result.product.next_id ? null : t.data.result.product.next_id,
                    bigPicUrl: 0 !== t.data.result.product.attr[0].length ? t.data.result.product.attr[0].url : ""
                });
            }
        });
    },
    offPicLayer: function() {
        this.setData({
            picLayer: !1
        });
    },
    switchTab: function(t) {
        this.setData({
            "options.cateId": this.data.cates[t.detail.current].id,
            listId: this.data.cates[t.detail.current].id,
            currCate: t.detail.current
        });
    },
    nextChoose: function(a) {
        var e = a.target.dataset.id;
        if (null !== e) {
            var r = this;
            t.request({
                url: t.server + "/productApi/getProductInfo",
                method: "POST",
                data: {
                    id: e
                },
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                success: function(t) {
                    console.log(t), r.setData({
                        chooseData: t.data.result.product,
                        lastId: 0 === t.data.result.product.last_id ? null : t.data.result.product.last_id,
                        nextId: 0 === t.data.result.product.next_id ? null : t.data.result.product.next_id,
                        bigPicUrl: 0 !== t.data.result.product.attr.length ? t.data.result.product.attr[0].url : ""
                    });
                }
            });
        }
    },
    chooseColor: function(t) {
        var a = this;
        this.setData({
            bigPicUrl: a.data.chooseData.attr[t.currentTarget.dataset.colorx].url
        });
    },
    toPlay: function(t) {
        wx.navigateTo({
            url: "/pages/play/play?id=" + this.data.chooseData.id
        });
    },
    onShareAppMessage: function() {}
});